using RockHopper.Common.Commanding;
using RockHopper.Common.Data;
using RockHopper.Common.Events;
using RockHopper.Common.Model;
using RockHopper.Common.ViewModel;

namespace RockHopper.TrainingCalculator.WinRT.ViewModel
{
    public class UnitsViewModel : ViewModelBase
    {
        private readonly ISettingsRepository settingsRepository;
        
        public UnitsViewModel(ISettingsRepository settingsRepository)
        {
            this.settingsRepository = settingsRepository;
            KilometresCommand = new DelegateCommand(() => ChangeUnits(PaceUnitType.Kilometres));
            MilesCommand = new DelegateCommand(() => ChangeUnits(PaceUnitType.Miles));
        }                
        
        public DelegateCommand KilometresCommand { get; private set; }
        
        public DelegateCommand MilesCommand { get; private set; }
        
        public void ChangeUnits(PaceUnitType units)
        {
            if (settingsRepository.PaceUnits != units)
            {
                settingsRepository.PaceUnits = units;
                DomainEvents.RaisePaceUnitsChanged(this, new PaceUnitsChangedEventArgs(units));
            }
        }
    }
}